package com.sky.financelake.ui.activity;

import android.os.Bundle;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;
import com.sky.financelake.R;
import com.sky.financelake.adapter.CommunityTabAdapter;
import com.sky.financelake.base.BaseA;
import com.sky.financelake.databinding.ActivityTestBinding;
import com.sky.financelake.ui.fragment.community.BarF;
import com.sky.financelake.ui.fragment.community.SkillF;
import com.sky.financelake.ui.fragment.community.TalkF;

import java.util.ArrayList;
import java.util.List;

import dagger.hilt.android.AndroidEntryPoint;

@AndroidEntryPoint
public class TabA extends BaseA {


    private ActivityTestBinding binding;
    private ViewPager2 viewPager2;
    private TabLayout tabLayout;
    private CommunityTabAdapter adapter;
    private List<Fragment> fragments = new ArrayList<>();
    private String[] tabs ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityTestBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        tabs = getResources().getStringArray(R.array.community_tabs);

        fragments.add(SkillF.newInstance());
        fragments.add(BarF.newInstance());
        fragments.add(TalkF.newInstance());

        viewPager2 = binding.viewPager2;
        tabLayout = binding.tabs;

        adapter = new CommunityTabAdapter(TabA.this,fragments);
        viewPager2.setAdapter(adapter);

        viewPager2.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                super.onPageScrolled(position, positionOffset, positionOffsetPixels);
            }

            @Override
            public void onPageSelected(int position) {
                super.onPageSelected(position);
                Toast.makeText(TabA.this, ""+position, Toast.LENGTH_SHORT).show();
            }
        });

        TabLayoutMediator tm = new TabLayoutMediator(tabLayout, viewPager2, new TabLayoutMediator.TabConfigurationStrategy() {
            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                tab.setText(tabs[position]);
            }
        });
        tm.attach();

    }

    private void initUI() {


    }

}
